package org.simtube.util;

import java.util.Comparator;

public class NormalizedCosineComparator implements Comparator<DocItem> {

	private DocVector query;
	
	public NormalizedCosineComparator(DocVector query) {
		this.query = query;
	}
	
	@Override
	public int compare(DocItem v1, DocItem v2) {
		DocVector nv1 = v1.vector.multiply(1 / v1.vector.norm());
		DocVector nv2 = v2.vector.multiply(1 / v2.vector.norm());
		
		return Double.compare(nv1.multiply(query), nv2.multiply(query));
	}

}
